/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package entities.tools;

import entities.users.CompanyOwner;
import entities.users.FormOwner;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;

/**
 *
 * @author Marek
 */
@Entity
public class Form implements Serializable {
    private static final long serialVersionUID = 1L;
    /**
     * 
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)   
    private Long id;
 
    //TODO: Change the collection to a the HashMap (key->question id,value -> Question)
    /**
     * 
     */
    @OneToMany(cascade=(CascadeType.ALL), fetch=FetchType.EAGER, mappedBy = "form", orphanRemoval = true)
    @OrderBy("orderNumber asc")
    private List<Question> questions = new ArrayList<>();
    /**
     * 
     */
    @OneToMany(cascade=(CascadeType.ALL),fetch = FetchType.LAZY, mappedBy = "form")
    private List<FilledForm> filledForms = new ArrayList<>();
    
    /**
     * 
     */
    @ManyToOne
    private CompanyOwner companyOwner;
    
    /**
     * 
     */
    @ManyToOne
    private FormOwner formOwner;
    
    /**
     * 
     */
    private String name="";
    
    /**
     * 
     */
    @Lob
    private String description="";
    
    /**
     * 
     * @return id 
     */
    public Long getId() {
        return id;
    }

    /**
     * 
     * @param id 
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * 
     * @return hash 
     */
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    /**
     * 
     * @param object
     * @return 
     */
    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Form)) {
            return false;
        }
        Form other = (Form) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    /**
     * 
     * @return the string representation of the Form entity 
     */
    @Override
    public String toString() {
        return "entities.Form[ id=" + id + " ]";
    }

    /**
     * @return the questions
     */
    public List<Question> getQuestions() {
        return questions;
    }

    /**
     * @param questions the questions to set
     */
    public void setQuestions(List<Question> questions) {
        this.questions = questions;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @return the filledForms
     */
    public List<FilledForm> getFilledForms() {
        return filledForms;
    }

    /**
     * @param filledForms the filledForms to set
     */
    public void setFilledForms(List<FilledForm> filledForms) {
        this.filledForms = filledForms;
    }

    /**
     * @return the companyOwner
     */
    public CompanyOwner getCompanyOwner() {
        return companyOwner;
    }

    /**
     * @param companyOwner the companyOwner to set
     */
    public void setCompanyOwner(CompanyOwner companyOwner) {
        this.companyOwner = companyOwner;
    }

    /**
     * @return the FormOwner
     */
   public FormOwner getFormOwner() {
        return formOwner;
    }

    /**
     * @param formOwner the agent to set
     */
    public void setFormOwner(FormOwner formOwner) {
        this.formOwner = formOwner;
    }

    /**
     * @return the description
     */
    public String getDescription() {
        return description;
    }

    /**
     * @param description the description to set
     */
    public void setDescription(String description) {
        this.description = description;
    }
    
}
